﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using ESRI.ArcGIS.Client;
using Eaglight.Extentions;
using ESRI.ArcGIS.Client.Symbols;

namespace Eaglight.Behaviors
{
    public class ZoomInBehavior : Behavior<Map>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.Cursor = Cursors.Stylus;
            Draw draw = this.AssociatedObject.GetDrawObject();
            draw.DrawMode = DrawMode.Rectangle;
            draw.LineSymbol = new SimpleLineSymbol();
            draw.DrawComplete += new EventHandler<DrawEventArgs>(draw_DrawComplete);
            draw.Map = this.AssociatedObject;
            draw.IsEnabled = true;
        }

        protected override void OnDetaching()
        {
            AssociatedObject.Cursor = Cursors.Arrow;
            Draw draw = this.AssociatedObject.GetDrawObject();
            draw.IsEnabled = false;
        }

        void draw_DrawComplete(object sender, DrawEventArgs e)
        {
            if (AssociatedObject != null)
            {
               this.AssociatedObject.ZoomTo(e.Geometry.Extent);
            }
        }
    }
}
